import { Controller } from 'egg';

class SetSQL{
    stype:string;
    sno:number;
    sql:string;
}

export default class StaticsController extends Controller {
    public async setStatics() {
        const { ctx } = this;
        let sqls :SetSQL[]| null  = ctx.request.body;
        if(sqls && sqls.length > 0){
            sqls.forEach((sql)=>{
                ctx.model.Statics.destroy({
                    where:{
                        stype:sql.stype,
                        sno:sql.sno,
                    }
                }).finally(()=>{
                    ctx.model.create(sql)
                })
                
            })
        }
    };
    public async getStatics(){
        const { ctx } = this;
        let res = await ctx.model.Statics.findAll();
        if(res){
            ctx.body = {result:res};
        }else{
            ctx.body = {result:[]};
        }
    };
    
}